package com.it.travel.controller.admin;

import com.it.travel.common.RequiredPermission;
import com.it.travel.pojo.User;
import com.it.travel.service.admin.AdminUserService;
import com.it.travel.vo.Params.PageParams;
import com.it.travel.vo.Params.admin.AdminUserParams;
import com.it.travel.vo.Params.admin.AdminUserUpdateParams;
import com.it.travel.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/admin/user")
@CrossOrigin
public class AdminUserController {
    @Resource
    private AdminUserService adminUserService;
    @RequiredPermission("sys:user:find")
    @GetMapping("")
    public Result<?> getUserInfoPage(PageParams pageParams) {
        Result<?> result = adminUserService.getUserInfoPage(pageParams);
        return result;
    }

    @RequiredPermission("sys:user:add")
    @PostMapping("")
    public Result<?> save(@RequestBody AdminUserParams adminUserParams) {
        Result<?> result = adminUserService.save(adminUserParams);
        return result;
    }
    @RequiredPermission("sys:user:delete")
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable("id") Integer id) {
        Result<?> result = adminUserService.delete(id);
        return result;
    }
    @RequiredPermission("sys:user:update")
    @PutMapping("")
    public Result<?> update(@RequestBody AdminUserUpdateParams adminUserUpdateParams) {
        Result<?> result = adminUserService.update(adminUserUpdateParams);
        return result;
    }
    @RequiredPermission("sys:user:delete")
    @PostMapping("/deletebatch")
    public Result<?> deletebatch(@RequestBody List<Integer> ids) {
        Result<?> result = adminUserService.deletebatch(ids);
//        request.get
        return result;
//        System.out.println("ids = " + ids);
//        return null;
        }
}
